<template>
  <div class="synchronous">
    <div class="content">
      <div class="plantime">
        <div class="left">
          <el-form label-width="auto" inline>
                <el-form-item label="角色名称:">
                 <el-input
                 v-model='inputValue1'
                   placeholder="请输入"
                   size="mini"
                   style="width: 150px"
                 ></el-input>
               </el-form-item>
               <el-form-item label="姓名:">
                 <el-input
                  v-model='inputValue2'
                   placeholder="请输入"
                   size="mini"
                   style="width: 150px"
                 ></el-input>
               </el-form-item>
               <el-form-item label="手机号:">
                 <el-input
                   placeholder="请输入"
                    v-model='inputValue3'
                   size="mini"
                   style="width: 150px"
                 ></el-input>
               </el-form-item>
               <el-form-item label="所属组织机构:" style="margin-left:10px">
                  <el-select
                    v-model="listQuery.type"
                    placeholder="请选择"
                    clearable
                    class="filter-item"
                    style="width:150px"
                    size="mini"
                 
                  >
                    <el-option
                      v-for="item in calendarTypeOptions"
                      :key="item.key"
                      :label="item.display_name + '(' + item.key + ')'"
                      :value="item.key"
                    />
                  </el-select>
                </el-form-item>
           </el-form>
        </div>
        <div class="right">
          <el-button
            v-waves
            class="filter-item"
            type="primary"
            icon="el-icon-search"
            @click="handleFilter"
          >
            查询
          </el-button>
        </div>
      </div>

      <!-- ---- -->
      <div class="contentT">
        <el-table
          height="750"
          :key="tableKey"
          v-loading="listLoading"
          :data="list"
          :header-cell-style="{
            background: '#EAF1FF',
            'text-align': 'center',
            color: '#000',
          }"
          :cell-style="{ 'text-align': 'center' }"
          fit
          highlight-current-row
          @sort-change="sortChange"
          style="width: 100%"
          :border="false"
        >
          <el-table-column
            label="序号"
            prop="id"
            sortable="custom"
            align="center"
            width="80"
          >
            <template slot-scope="{ row }">
              <span>{{ row.id }}</span>
            </template>
          </el-table-column>
          <el-table-column label="账号" width="542">
            <template slot-scope="{ row }">
              <span>{{ row.author }}</span>
            </template>
          </el-table-column>

          <el-table-column label="姓名" width="379" align="center">
            <template slot-scope="{ row }">
              <span style="color: red">{{ row.reviewer }}</span>
            </template>
          </el-table-column>

          <el-table-column label="手机号" align="center" width="284">
            <template slot-scope="{ row }">
              <span>{{ row.pageviews }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="所属组织机构"
            class-name="status-col"
            width="auto"
          >
            <template slot-scope="{ row }">
              <el-tag :type="row.status | statusFilter">
                {{ row.status }}
              </el-tag>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="listQuery.page"
          :limit.sync="listQuery.limit"
          @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { fetchList, fetchPv } from "@/api/article";
import waves from "@/directive/waves"; // waves directive
import { parseTime } from "@/utils";
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination

const calendarTypeOptions = [
  { key: "CN", display_name: "China" },
  { key: "US", display_name: "USA" },
  { key: "JP", display_name: "Japan" },
  { key: "EU", display_name: "Eurozone" },
];
// arr to obj, such as { CN : "China", US : "USA" }
const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name;

  return acc;
}, {});

export default {
  name: "ComplexTable",
  components: { Pagination },
  directives: { waves },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: "success",
        draft: "info",
        deleted: "danger",
      };
      return statusMap[status];
    },
    typeFilter(type) {
      return calendarTypeKeyValue[type];
    },
  },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
         inputValue1:'',
   inputValue2:'',
   inputValue3:'',

      listQuery: {
        page: 1,
        limit: 20,

        importance: undefined,
        title: undefined,
        type: undefined,
        sort: "+id",
      },
      calendarTypeOptions,
      temp: {
        id: undefined,
        importance: 1,
        remark: "",
        timestamp: new Date(),
        title: "",
        type: "",
        status: "published",
      },

      downloadLoading: false,
    };
  },
  created() {
    this.getList();
    // console.log(this.temp);
  },
  mounted() {
    // this.$eventBus.$on("zipao", () => {
    //   (this.showlist = true), (this.showdetail = false);
    // });
  },
  methods: {
    getList() {
      this.listLoading = true;
      fetchList(this.listQuery).then((response) => {
        console.log(response);
        this.list = response.data.items;
        this.total = response.data.total;

        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false;
        }, 1.5 * 1000);
      });
    },

    // 搜索
    handleFilter() {
      this.data.kssj = this.timeDate == null ? "" : this.timeDate[0];
      this.data.jssj = this.timeDate == null ? "" : this.timeDate[1];
      console.log(this.data);

      this.listQuery.page = 1;
      this.getList();
    },

    // handleModifyStatus(row, status) {
    //   this.$message({
    //     message: "操作成功",
    //     type: "success",
    //   });
    //   row.status = status;
    // },
    sortChange(data) {
      const { prop, order } = data;
      if (prop === "id") {
        this.sortByID(order);
      }
    },
    sortByID(order) {
      if (order === "ascending") {
        this.listQuery.sort = "+id";
      } else {
        this.listQuery.sort = "-id";
      }
      this.handleFilter();
    },
    resetTemp() {
      this.temp = {
        id: undefined,
        importance: 1,
        remark: "",
        timestamp: new Date(),
        title: "",
        status: "published",
        type: "",
      };
    },

    getSortClass: function (key) {
      const sort = this.listQuery.sort;
      return sort === `+${key}` ? "ascending" : "descending";
    },
  },
};
</script>

<style lang='scss' scoped>
@import "@/styles/Fadeinout.scss";
.synchronous {
  padding: 20px;
  .plantime {
    background-color: #fff;
    width: 100%;
    height: 64px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: center;
    padding: 20px;
    font-size: 14px;
    box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
    .left {
      margin-top: 22px;
    }
  }
  .contentT {
    box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    background-color: #fff;
    height: 100%;
    width: 100%;
    padding: 20px;

    .tips {
      width: 100%;
      height: 22px;
      font-size: 16px;
      // margin-left: 20px;
      font-weight: 500;
      color: #5084fb;
      line-height: 22px;
      margin-bottom: 20px;
    }
  }
}
</style>